<?php
/**
* @file $Id: IncompleteSchedules.php 161 2006-09-07 06:21:17Z doritojones $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

DrawHeader(ProgramTitle());

if(!$_REQUEST['mp'])
{
	if(!$_REQUEST['mp'] && GetMP(UserMP(),'POST_START_DATE'))
		$_REQUEST['mp'] = UserMP();
	elseif(strpos(GetAllMP('QTR',UserMP()),str_replace('E','',$_REQUEST['mp']))===false && strpos(GetChildrenMP('PRO',UserMP()),"'".$_REQUEST['mp']."'")===false && GetMP(UserMP(),'POST_START_DATE'))
		$_REQUEST['mp'] = UserMP();
	
	if(!$_REQUEST['mp'] && GetMP(GetParentMP('SEM',UserMP()),'POST_START_DATE'))
		$_REQUEST['mp'] = GetParentMP('SEM',UserMP());	
}

$sem = GetParentMP('SEM',UserMP());
$fy = GetParentMP('FY',$sem);
$pro = GetChildrenMP('PRO',UserMP());
$pros = explode(',',str_replace("'",'',$pro));
$pro_grading = false;
$pro_select = '';
foreach($pros as $pro)
{
	if(GetMP($pro,'POST_START_DATE'))
	{
		if(!$_REQUEST['mp'])
			$_REQUEST['mp'] = $pro;
		$pro_grading = true;
		$pros_arr[] = $pro;
	}
}

if(GetMP(UserMP(),'POST_START_DATE'))
{
	$mps_arr[] = UserMP();
}
elseif($_REQUEST['mp']==UserMP())
	$_REQUEST['mp'] = $sem;

if(GetMP($sem,'POST_START_DATE'))
	$mps_arr[] = $sem;
if(GetMP($fy,'POST_START_DATE'))
	$mps_arr[] = $fy;

if($pro_grading)
{
	foreach($pros_arr as $mp)
		$mps_arr[] = $mp;
}

$tmp_REQUEST = $_REQUEST;
unset($tmp_REQUEST['mp']);

$tmp_PHP_SELF = PreparePHP_SELF($tmp_REQUEST);
if(count($mps_arr))
{
	foreach($mps_arr as $mp)
	{
		if($_REQUEST['mp']!==$mp)
		{
			$tabcolor = 'DFDFDF';
			$textcolor = '666666';
		}
		else
		{
			$tabcolor = Preferences('HIGHLIGHT');
			$textcolor = 'FFFFFF';
		}

		$header .= '<TD width=10></TD><TD>'.DrawTab(GetMP($mp),$tmp_PHP_SELF.'&amp;mp='.$mp.'&amp;LO_index='.$_REQUEST['LO_index'],$tabcolor,$textcolor,'_circle',array('tabcolor'=>Preferences('HIGHLIGHT'),'textcolor'=>'FFFFFF')).'</TD>';
	}
}
else
	$header .= _('There are no marking periods available for taking grades.');

echo TabsHeader($header);

Widgets('all');

$extra['SELECT'] .= ',gc.TITLE AS COURSE_TITLE,gcp.TEACHER_ID,gcp.PERIOD_ID,gss.START_DATE,gss.END_DATE';
$extra['FROM'] .= ',SCHEDULE gss,COURSES gc,COURSE_PERIODS gcp';
$extra['WHERE'] .= " AND gcp.DOES_GRADES='Y' AND gc.COURSE_ID=gss.COURSE_ID AND gcp.COURSE_PERIOD_ID=gss.COURSE_PERIOD_ID AND gss.STUDENT_ID=ssm.STUDENT_ID AND gss.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).") AND NOT EXISTS (SELECT '' FROM STUDENT_REPORT_CARD_GRADES gsrcg WHERE gss.STUDENT_ID=gsrcg.STUDENT_ID AND gss.COURSE_PERIOD_ID=gsrcg.COURSE_PERIOD_ID AND gsrcg.MARKING_PERIOD_ID='".$_REQUEST['mp']."')";

$extra['columns_after'] = array('COURSE_TITLE'=>_('Course'),'TEACHER_ID'=>'Teacher','PERIOD_ID'=>'Period','START_DATE'=>_('Start Date'),'END_DATE'=>_('End Date'));

$extra['functions']['TEACHER_ID'] = 'getTeacher';
$extra['functions']['PERIOD_ID'] = 'getPeriod';
$extra['functions']['START_DATE'] = $extra['functions']['END_DATE'] = 'ProperDate';
$extra['link']['FULL_NAME'] = false;

$extra['singular'] = _('missing grade');
$extra['plural'] = _('missing grades');

Search('student_id',$extra);

?>